﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;

namespace ISchool
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            //ArcGIS的使用许可
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

            //ArcGIS扩展模块使用许可
            IAoInitialize m_aoinitialize = new AoInitializeClass();
            m_aoinitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

            Application.SetCompatibleTextRenderingDefault(false);

            #region 资源异常则自主加载资源
            //作者：代兴梅
            //判断是否资源是否就绪
            Initialization Init = new Initialization();
            if (Init.IsAllow)
            {
                //就绪则加载窗体
                Application.Run(new Form1());
            }
                //否则获取GDB数据库文件夹和卫星底图影像
            else
            {
                if (Init.NoType == Initialization.ShortType.GDB_SHPandTIFF)
                {
                    FolderBrowserDialog IFolder = new FolderBrowserDialog();
                    IFolder.Description = "获取Gdb文件数据库";
                    if (IFolder.ShowDialog() == DialogResult.OK && System.IO.Path.GetExtension(IFolder.SelectedPath) == "gdb")
                    {
                        Initialization.dGdbPath = IFolder.SelectedPath;
                    }
                    OpenFileDialog IOpenFile = new OpenFileDialog();
                    IOpenFile.Title = "设置默认卫星地图数据";
                    IOpenFile.Filter = "图像文件（*.bmp,*jpg,*.img,*.tif）|*.bmp;*.jpg;*.img;*.tif";
                    IOpenFile.Multiselect = false;
                    if(IOpenFile.ShowDialog()==DialogResult.OK)
                    {
                        Initialization.dTiffPath = IOpenFile.FileName;
                    }
                }
                else if (Init.NoType == Initialization.ShortType.GDB_SHP)
                {
                    FolderBrowserDialog IFolder = new FolderBrowserDialog();
                    IFolder.Description = "获取Gdb文件数据库";
                    if (IFolder.ShowDialog() == DialogResult.OK && System.IO.Path.GetExtension(IFolder.SelectedPath) == "gdb")
                    {
                        Initialization.dGdbPath = IFolder.SelectedPath;
                    }
                }
                else
                {
                    OpenFileDialog IOpenFile = new OpenFileDialog();
                    IOpenFile.Title = "设置默认卫星地图数据";
                    IOpenFile.Filter = "图像文件（*.bmp,*jpg,*.img,*.tiff）|*.bmp;*.jpg;*.img;*.tiff";
                    IOpenFile.Multiselect = false;
                    if (IOpenFile.ShowDialog() == DialogResult.OK)
                    {
                        Initialization.dTiffPath = IOpenFile.FileName;
                    }
                }
                //参数准备完毕，重新进入程序
                Application.Run(new Form1());
            }

            #endregion

        }
    }
}
